<?php

require_once BaseUtil::getModulePath("base")  .  '/forms/BaseForm.php';

class AdminEditForm extends BaseForm {
    public function __construct ($departments,$permissions,$admin = array(),$adminDepartments = array(),$adminPermissions = array())
    {
        parent::__construct();
        $this->setAction(HttpUtil::getUrl("admin", "subedit"));

        //id
        $id = new Zend_Form_Element_Hidden('adminId');
        $id->setValue($admin['id']);
        $this->addElement($id);
        // username
        $name = new Zend_Form_Element_Text('name');
        $name->setLabel($this->translate->_('userName'));
        $name->addFilter("StringTrim");
        $name->setRequired(true);
        $name->setValue($admin['username']);
        // passwrod
        $password = new Zend_Form_Element_Password('password');
        $password->setLabel($this->translate->_('password'));
        $password->addFilter("StringTrim");
        //$password->setRequired(true);
        //$password->addValidator();
        //email
        $email = new Zend_Form_Element_Text('email');
        $email->setLabel($this->translate->_('userEmail'));
        $email->addFilter("StringTrim");
        $email->setRequired(true);
        $email->addValidator('EmailAddress');
        $email->setValue($admin['email']);

        //unique validate
        $validUnique = new MyValid_Unique();
        $validUnique->setTableName('admins');
        $validUnique->setFieldName('email');
        $validUnique->setId($admin['id']);
        $email->addValidator($validUnique);

        //permissions
        $permission = new Zend_Form_Element_MultiCheckbox("permission");
        $permission->setLabel($this->translate->_('permission'));
        $permission->setMultiOptions($permissions);
        //$permission->setRequired(true);
        $permission->setValue($adminPermissions);
        
        //departments
        $depChkbox = new Zend_Form_Element_MultiCheckbox("department");
        $depChkbox->setLabel($this->translate->_('department'));
        $depChkbox->setRequired(true);
        $depChkbox->setMultiOptions($departments);
        $depChkbox->setValue($adminDepartments);

        //status
        $status = new Zend_Form_Element_Select('status');
        $status->setLabel($this->translate->_('userStatus'));
        $status->setMultiOptions(array("1"=> $this->translate->_('statusA') ,"0"=> $this->translate->_('statusI')));
        $status->setValue($admin['status']);
        
        
        $this->addElements(array($name,$password,$email,$status,$permission,$depChkbox));

        $this->setElementDecorators(array(
            'ViewHelper',
            array(array('div' => 'HtmlTag'), array('tag' => 'div',"class" => "form_element")),
        ));

    }
}